function HandlePageBackendPayees(gui, operator, now, options) {
  this._gui = gui;
  this._operator = operator;
  this._now = now;
  this._options = options;
  
  this._createElements();
};

HandlePageBackendPayees.prototype._createElements = function() {
  var _self = this;
  this._gui.add.onclick = function() { if (_self._operator.type == Constant.USER_TYPE_STAFF) {
                                         location.href = '?p=pagestaff&t=pagebackendpayee&m=' + JSON.stringify({ a: 2, b: 3 }); 
                                       } else {
                                         location.href = '?p=pageadmin&t=pagebackendpayee&m=' + JSON.stringify({ a: 2, b: 3 }); 
                                       }
                                     };
  this._loadData();
};

HandlePageBackendPayees.prototype._loadData = function() {
  var tr, td;
  tr = this._gui.result.insertRow(-1);
  td = tr.insertCell(-1);
  td.colSpan = 2;
  tr.style.backgroundColor = '#fff';
  td.style.borderRight = 'solid 1px #694247';
  td.style.borderBottom = 'solid 1px #694247';
  td.style.borderLeft = 'solid 1px #694247';
  td.appendChild(DOMUtils.getLoadingImage());
  
  this._payees = null;
  this._retrievePayees();
};

HandlePageBackendPayees.prototype._verifyData = function() {
  if (this._payees) {
    this._updateElements();
  }
};

HandlePageBackendPayees.prototype._retrievePayees = function() {
  var _self = this;
  new RequestUtils()._read('pz_payee', null, null, null, null, 'd.name', null, function(result, params) { _self._payees = result.data;
                                                                                                          _self._verifyData.call(_self);
                                                                                                        }, null);
};

HandlePageBackendPayees.prototype._updateElements = function() {
  var tr, td, _self = this;
  DOMUtils.removeTableRows(this._gui.result, 1);
  
  if (this._payees.length == 0) {
    tr = this._gui.result.insertRow(-1);
    td = tr.insertCell(-1);
    td.colSpan = 2;
    td.style.height = '24px';
    td.style.textAlign = 'center';
    td.style.borderRight = 'solid 1px #694247';
    td.style.borderLeft = 'solid 1px #694247';
    td.style.borderBottom = 'solid 1px #694247';
    td.style.backgroundColor = '#fff';
    td.appendChild(document.createTextNode('N/A'));
  }
  
  MiscUtils.sort(this._payees, ['name']);
  for(var i = 0, il = this._payees.length; i < il; i++) {
    var p = this._payees[i];
    tr = this._gui.result.insertRow(-1);
    tr.style.backgroundColor = (tr.rowIndex % 2 != 0) ? '#fff' : '#faf9f4';
    
    td = tr.insertCell(-1);
    td.align = 'left';
    td.style.height = '24px';
    td.style.borderRight = 'solid 1px #694247';
    td.style.borderBottom = 'solid 1px #694247';
    td.style.borderLeft = 'solid 1px #694247';
    td.style.padding = '0 0 0 20px';
    var a = document.createElement('a');
    if (this._operator.type == Constant.USER_TYPE_STAFF) {
      a.href = '?p=pageasst&t=pagebackendpayee&m=' + JSON.stringify({ a:2, b:3 }) + '&opts=' + JSON.stringify({ id: p.id });
    } else {
      a.href = '?p=pageadmin&t=pagebackendpayee&m=' + JSON.stringify({ a:2, b:3 }) + '&opts=' + JSON.stringify({ id: p.id });
    }
    a.appendChild(document.createTextNode(p.name));
    td.appendChild(a);
    
    td = tr.insertCell(-1);
    td.align = 'center';
    td.style.height = '24px';
    td.style.borderRight = 'solid 1px #694247';
    td.style.borderBottom = 'solid 1px #694247';
    var img = document.createElement('img');
    img.src = 'images/common/delete.png';
    img.style.cursor = 'pointer';
    img._p = p;
    img.onclick = function() { new RequestUtils()._write('pz_payee', [], [this._p], function() { _self._retrievePayees(); }, {pos: DOMUtils.findPos(this)}); };
    td.appendChild(img);
  }
};

